struct KMP {
	KMP() {}
	KMP(const string s) {
		init(s);
	}

	void init(string s) {
		int n = s.size();
		nexs.resize(n);
		nexs[0] = nexs[1] = 0;

		for (int i = 2, j = 0; i < n; i++) {
			while (j && s[i] != s[j + 1]) {
				j = nexs[j];
			}
			if (s[i] == s[j + 1]) {
				j++;
			}
			nexs[i] = j;
		}
		this->s = s;
	}

	vector<int> match(string p) {
		vector<int> pos;
		int n = p.size();
		for (int i = 1, j = 0; i < n; i++) {
			while (j && p[i] != s[j + 1]) {
				j = nexs[j];
			}
			if (p[i] == s[j + 1]) {
				j++;
			}
			if (j == (int)s.size() - 1) {
				pos.emplace_back(i - j + 1);
				j = nexs[j];
			}
		}
		return pos;
	}

  vector<int> get_next() {
    return nexs;
  }

  vector<vector<int>> get_next_all() {
    int n = s.size();
    vector<vector<int>> nex(n, vi(26, 0));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        if (i + 1 < n && (s[i + 1] - 'a') == j) {
          nex[i][j] = i + 1;
        } else {
          nex[i][j] = nex[nexs[i]][j];
        }
      }
    }
    return nex;
  };

	string s;
	vector<int> nexs;
};

const int inf = 1e9;
void solve()
{
  string c;
  cin >> c;

  string s, t;
  cin >> s >> t;

  int n = sz(s), m = sz(t);
  s = " " + s, t = " " + t;
  KMP kmps(s), kmpt(t);

  auto nexs = kmps.get_next_all();
  auto next = kmpt.get_next_all();
  vvi dp(n + 1, vi(m + 1, -inf));
  dp[0][0] = 0;

  rep(i, 0, sz(c) - 1) {
    vvi ndp(n + 1, vi(m + 1, -inf));
    rep(j, 0, n) {
      rep(k, 0, m) {
        if (c[i] != '*') {
          int v = c[i] - 'a', w = 0;
          if (nexs[j][v] == n) {
            w++;
          }
          if (next[k][v] == m) {
            w--;
          }
          ndp[nexs[j][v]][next[k][v]] = max(ndp[nexs[j][v]][next[k][v]], dp[j][k] + w);
        } else {
          rep(v, 0, 25) {
            int w = 0;
            if (nexs[j][v] == n) {
              w++;
            }
            if (next[k][v] == m) {
              w--;
            }
            ndp[nexs[j][v]][next[k][v]] = max(ndp[nexs[j][v]][next[k][v]], dp[j][k] + w);
          }
        }
      }
    }
    dp.swap(ndp);
  }

  int ans = -inf;
  rep(i, 0, n) {
    rep(j, 0, m) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}